import prisma from '../lib/prisma';

export enum UserRole {
  ADMIN = 'ADMIN',
  TEACHER = 'TEACHER',
  STUDENT = 'STUDENT'
}

export interface User {
  id: string;
  email: string;
  name: string;
  role: UserRole;
  createdAt: Date;
  updatedAt: Date;
  isActive?: boolean;
}

export type PrismaTransaction = Omit<
  typeof prisma,
  '$connect' | '$disconnect' | '$on' | '$transaction' | '$use'
>;

export interface PrismaClientKnownRequestError extends Error {
  code: string;
  clientVersion: string;
  meta?: Record<string, unknown>;
}

export type PrismaError = PrismaClientKnownRequestError;

// Type Guards
export function isPrismaError(error: unknown): error is PrismaError {
  return Boolean(
    error &&
    typeof error === 'object' &&
    'code' in error &&
    error instanceof Error &&
    'clientVersion' in error
  );
}

// Database operation types
export interface DatabaseOperations {
  user: {
    findMany: typeof prisma.user.findMany;
    findUnique: typeof prisma.user.findUnique;
    create: typeof prisma.user.create;
    update: typeof prisma.user.update;
    delete: typeof prisma.user.delete;
    count: typeof prisma.user.count;
  };
}

// Common types
export type WhereUniqueInput = { id: string } | { email: string };
export type WhereInput = Record<string, unknown>;
export type DataInput = Record<string, unknown>;
export type SelectInput = Record<string, boolean>;
